package com.kx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kx.entity.GoodsCategory;
import com.kx.mapper.GoodsCategoryMapper;
import com.kx.service.GoodsCategoryService;
import com.kx.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsCategoryServiceImpl implements GoodsCategoryService {
    @Autowired
    private GoodsCategoryMapper goodsCategoryMapper;

    @Override
    public DataVO<GoodsCategory> findGoodsCategory() {
        DataVO<GoodsCategory> dataVO = new DataVO<>();
        //1、设置code
        dataVO.setCode(0);
        //2、设置msg
        dataVO.setMsg("");
        //3、设置count(如果使用了mybatis-plus分页，则不需要调用其中selectCount方法单独调用)
        dataVO.setCount(Long.valueOf(goodsCategoryMapper.selectCount(null)));
        //4、设置data
        List<GoodsCategory> goodsCategoryList = goodsCategoryMapper.selectList(null);
        dataVO.setData(goodsCategoryList);

        return dataVO;
    }

    @Override
    public List<GoodsCategory> findGoodsCategoryList() {
        return goodsCategoryMapper.selectList(null);
    }

    @Override
    public GoodsCategory findGoodCategoryById(Integer id) {
        QueryWrapper<GoodsCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        return goodsCategoryMapper.selectOne(queryWrapper);
    }

    @Override
    public GoodsCategory findGoodCategoryByName(String name) {
        QueryWrapper<GoodsCategory> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("name",name);
        return goodsCategoryMapper.selectOne(queryWrapper);
    }

}
